package com.gitee.huanminabc.utils_tools.security.core;

import com.gitee.huanminabc.jcommon.exception.BizException;
import com.gitee.huanminabc.utils_tools.security.vo.LoginUserVo;
import org.springframework.security.core.context.SecurityContextHolder;
//获取登录用户信息
//获取登录信息
//登陆用户
//当前用户
public class ContextHolder {

    public  static LoginUserVo CurrentUser(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof LoginUserVo) {
            LoginUserVo loginUserDto = (LoginUserVo) principal;
            loginUserDto.setAuthorities(null);
            loginUserDto.getSysUser().setPassword(null);
            return loginUserDto;
        }
        throw new BizException("获取登录用户信息失败");
    }
    //清除当前用户信息
    public static void clearCurrentUser(){
        SecurityContextHolder.clearContext();
    }
}
